﻿using System;

namespace CSExample {
	public static class VirtualDemo {
		public static void Run () {
			A p = new B ();
			B p1 = new B ();

			//new: 父类不改变
			p.Fun ();	//"I am F in A"
			p1.Fun ();	//"I am F in B"

			//override：父类改变
			p.Gun ();       //"I am G in B"
			p1.Gun ();      //"I am G in B"
		}


		class A {
			public void Fun () {
				Console.WriteLine ("I am F in A");
			}

			public virtual void Gun () {
				Console.WriteLine ("I am G in A");
			}
		}

		class B : A {
			new public void Fun () {
				Console.WriteLine ("I am F in B");
			}

			public override void Gun () {
				Console.WriteLine ("I am G in B");
			}
		}
	}
}

